*12345678901234567890123456789012345678901234567890123456789012345678901234567890

*	************************************************************************
* 	File-Name: 	Rosenberg_et_al_dataprocessing_code.do
*	Date:  		10/24/2019
*	Author: 	Meital Rosenberg, Daniel Armanios, Michaël Aklin, Paulina
*				Jaramillo
*	Data Used:  ACCESS-1
*	Purpose:   	.do file to generate new variables and dataset.
*	************************************************************************


*	************************************************************************
*	1. Coding: code new variables
*	************************************************************************

* 	Creating a dummy for households where the woman is the head. 
*	Unclear case are missing.
gen woman_hhhead = 0
replace woman_hhhead = 1 if m1_q38_decision_maker == 2

*	Reverse code females
generate female=1 if m1_q20_gender==0
replace female=0 if m1_q20_gender==1

*	Have kitchen (inferred)
gen kitchen = 1 if m4_q117_cook_location==0
replace kitchen = 0 if m4_q117_cook_location!=0

*	Total lights bulbs
egen total_lights=rowtotal(m2_q75_1_no_Incandescent_bulb m2_q75_2_no_cfl_bulb 	///
	m2_q75_3_no_led_light m2_q75_4_no_tube_light)
egen total_lightsfans=rowtotal(total_lights m2_q75_5_no_fans)
replace total_lights=. if m2_q75_5_no_fans==.
replace total_lightsfans=. if m2_q75_5_no_fans==.

*	Gender neutral appliances (water pump, non-kitchen bulb, and refrigerator) 
*	- separately test fans and bulbs
gen fridge_yesno=1 if m2_q75_7_no_fridges>=1 & m2_q75_7_no_fridges!=.
replace fridge_yesno=0 if m2_q75_7_no_fridges==0 & m2_q75_7_no_fridges!=.
gen pump_yesno=1 if m2_q75_14_no_elec_pump>=1 & m2_q75_14_no_elec_pump!=.
replace pump_yesno=0 if m2_q75_14_no_elec_pump==0 & m2_q75_14_no_elec_pump!=.

egen gender_neutral_category=rowtotal(fridge_yesno pump_yesno)
egen gender_neutral_category_alt=rowtotal(fridge_yesno m1_q50_pump_irrigation)
egen gender_neutral_total=rowtotal(m2_q75_7_no_fridges m2_q75_14_no_elec_pump)
replace gender_neutral_category=. if m2_q75_7_no_fridges==.
replace gender_neutral_category_alt=. if m2_q75_7_no_fridges==.
replace gender_neutral_total=. if m2_q75_7_no_fridges==.

*	Gender male usage (TV, mobile, non-kitchen fan) 
*	- separately test fans and bulbs
gen TV_yesno=1 if m2_q75_8_no_tvs>=1 & m2_q75_8_no_tvs!=.
replace TV_yesno=0 if m2_q75_8_no_tvs==0 & m2_q75_8_no_tvs!=.
gen mobile_yesno=1 if m2_q67_1_phone_no>=1 & m2_q67_1_phone_no!=.
replace mobile_yesno=0 if m2_q67_1_phone_no==0 & m2_q67_1_phone_no!=.

egen gender_male_category=rowtotal(TV_yesno mobile_yesno)
egen gender_male_category_alternative=rowtotal(TV_yesno m2_q67_phone)
egen gender_male_total=rowtotal(m2_q75_8_no_tvs m2_q67_1_phone_no)
replace gender_male_category=. if m2_q75_8_no_tvs==.
replace gender_male_category_alternative=. if m2_q75_8_no_tvs==.
replace gender_male_total=. if m2_q75_8_no_tvs==.

*	Gender female usage (grinder, sewing machine, mixer, iron, washing machine, 
*	kitchen light, kitchen fan) - separately test fans and bulbs
gen iron_yesno=1 if m2_q75_6_no_irons>=1 & m2_q75_6_no_irons!=.
replace iron_yesno=0 if m2_q75_6_no_irons==0 & m2_q75_6_no_irons!=.
gen wash_yesno=1 if m2_q75_11_no_wash_machine>=1 & m2_q75_11_no_wash_machine!=.
replace wash_yesno=0 if m2_q75_11_no_wash_machine==0 & m2_q75_11_no_wash_machine!=.
gen stove_yesno=1 if m2_q75_12_no_elec_stove>=1 & m2_q75_12_no_elec_stove!=.
replace stove_yesno=1 if m2_q75_12_no_elec_stove==0 & m2_q75_12_no_elec_stove!=.

gen genderkitchen_interact = m1_q20_gender*kitchen
gen womanheadkitchen_interact = woman_hhhead*kitchen
gen femalekitchen_interact=female*kitchen


*	Add grinders (very few of them)
gen grinder=1 if m2_q75_15_elec_other=="FLOUR GRINDER" | m2_q75_15_elec_other=="FLOUR GRINDER MACHINE" | m2_q75_15_elec_other=="FODDER CUTTER MACHINE" | m2_q75_15_elec_other=="MIXER GRINDER" | m2_q75_15_elec_other=="MIXER GRINDER MACHINE"
replace grinder=0 if grinder==.

egen gender_female_category=rowtotal(iron_yesno wash_yesno stove_yesno)
egen gender_female_total=rowtotal(m2_q75_6_no_irons m2_q75_11_no_wash_machine m2_q75_12_no_elec_stove)
replace gender_female_category=. if m2_q75_8_no_tvs==.
replace gender_female_total=. if m2_q75_8_no_tvs==.

*	Include grinder
egen gender_female_total_alt=rowtotal(m2_q75_6_no_irons m2_q75_11_no_wash_machine m2_q75_12_no_elec_stove grinder)
replace gender_female_total_alt=. if m2_q75_6_no_irons==.

*	Aggregate neutral and female
gen gender_female_alt2=gender_female_total_alt+gender_neutral_total

*	I solate gender to the mother and not kids (namely daughters) and compare 
*	only to spouse who is male
gen mother=1 if m1_q20_gender==0 & m1_q17_relationship==2
replace mother=0 if m1_q20_gender==1 & m1_q17_relationship==1

gen motherkitchen_interact=mother*kitchen

*	Isolate gender where female is considered head and husband is consider 
*	not head
gen mother_head=1 if m1_q20_gender==0 & m1_q17_relationship==1
replace mother_head=0 if m1_q20_gender==1 & m1_q17_relationship==2

gen motherheadkitchen_interact=mother_head*kitchen

*	Generate versions with zeros instead of missing (for households that
*	don't have electricity)
foreach q of varlist m2_q75_5_no_fans m2_q67_1_phone_no m2_q75_8_no_tvs gender_male_category gender_male_total gender_neutral_category gender_neutral_total gender_neutral_category_alt gender_female_total_alt gender_female_total gender_female_category total_lights total_lightsfans m2_q75_6_no_irons m2_q75_11_no_wash_machine m2_q75_12_no_elec_stove m2_q75_7_no_fridges m2_q75_14_no_elec_pump {
	gen `q'2=`q'
	replace `q'2=0 if `q'==. & m2_q68_elec==0
	}

*	Grid years ensuring those without electricity and non-grid electricity are 0 
*	(to be consistent with m2_q55_grid_use)
gen m2_q55_1_grid_years2 = m2_q55_1_grid_years
replace m2_q55_1_grid_years2 = 0 if m2_q55_1_grid_years2==. & m2_q68_elec==0
replace m2_q55_1_grid_years2 = 0 if m2_q55_1_grid_years2==. & m2_q69_elec_hrs>=1


*	************************************************************************
*	2. Save: new datasets
*	************************************************************************

saveold "RawDataHH_recoded.dta", v(12) replace


